<template>
  <div style="display: flex; flex-direction: column; height: 100%">
    <div class="warn-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        设备信息管理
      </h4>
      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="120px"
        id="elform"
        style="display: flex; flex-wrap: wrap"
      >
        <el-form-item
          label="设备名称："
          prop="sbmc"
          style="width: 400px; float: left"
        >
          <el-input
            v-model="formData.sbmc"
            placeholder="请输入设备名称"
            clearable
            style="float: left"
            :style="{ width: '75%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="设备id："
          prop="deviceId"
          style="width: 400px; float: left"
        >
          <el-input
            v-model="formData.deviceId"
            placeholder="请输入设备id"
            clearable
            style="float: left"
            :style="{ width: '75%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="绑定学校："
          prop="bdSchool"
          style="width: 400px; float: left"
        >
          <el-input
            v-model="formData.bdSchool"
            placeholder="请输入绑定学校名称"
            clearable
            style="float: left"
            :style="{ width: '75%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="添加人姓名："
          prop="deviceStatus"
          style="width: 400px; float: left"
        >
          <el-input
            v-model="formData.deviceStatus"
            placeholder="请输入添加人姓名"
            clearable
            style="float: left"
            :style="{ width: '75%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="添加时段："
          prop="time"
          style="width: 500px; float: left"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '280px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
            style="border: 1px red solid"
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="large" style="float: right">
          <el-button @click="resetForm()" id="reset">重置</el-button>
          <el-button
            type="primary"
            @click="submitForm(formData)"
            style="color: #ffffff; background-color: #126bff"
            id="submitForm"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="warn-content" style="width: 100%">
      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        style="width: 100%"
      >
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="sbmc" label="设备名称"> </el-table-column>
        <el-table-column prop="deviceid" label="设备id"> </el-table-column>
        <el-table-column prop="sbType" label="设备类型"> </el-table-column>
        <el-table-column prop="azdz" label="安装地址"> </el-table-column>
        <el-table-column prop="deviceStatus" label="设备状态">
          <template v-slot="scope">
            <!-- <el-tag size="medium">{{ scope.row.name }}</el-tag> -->
            <span
              size="medium"
              v-if="scope.row.status == 1"
              style="
                width: 70px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                color: #1cdc7c;
              "
              >在线</span
            >
            <span
              size="medium"
              v-if="scope.row.status == 0"
              style="
                width: 70px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                color: #ff4444;
              "
              >离线</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="addPeopleName" label="添加人姓名">
        </el-table-column>
        <el-table-column prop="bdschool" label="绑定学校"> </el-table-column>
        <el-table-column prop="time" label="添加时间" width="200">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
            <!-- <el-button type="text" size="small">编辑</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 2, 4, 8]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="tableData.length"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <div>
      <detailDialog
        :dialogVsible="Visible"
        :detail="detaile"
        :deviceVisible="deviceVisible"
        @handel="handel"
        @Confirm="Confirm"
      ></detailDialog>
    </div>
  </div>
</template>
<script>
import detailDialog from "@/components/detailDetail";

export default {
  deviceid: "WARN",
  components: { detailDialog },
  data() {
    return {
      Visible: false,
      deviceVisible: false,
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      currentPage4: 4,
      // pages: {
      // 按页数查询数据
      currentPage: 1,
      pageSize: 4,
      // },
      formData: {
        sbmc: "",
        deviceId: "",
        bdSchool: "",
        deviceStatus: "",
        time: "",
      },
      searchData: {
        sbmc: "",
        deviceId: "",
        bdSchool: "",
        deviceStatus: "",
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
      },
      detaile: {},
      tableData: [
        {
          sbmc: "RXSB-3320",
          deviceid: "489761789",
          sbType: "人像设备",
          bdSchool: "张三",
          azdz: "廊坊市第一小学",
          deviceStatus: "0",
          addPeopleName: "张宁",
          phone: "13313413888",
          relation: "哥哥",
          bdschool: "廊坊市第一小学",
          vistorAddress: "教学楼",
          time: "2023-07-21 15:30:56",
          status: "0",
        },
        {
          sbmc: "CLSB-4560",
          deviceid: "489761789",
          sbType: "车辆设备",

          bdSchool: "张三",
          azdz: "廊坊市第一小学",
          deviceStatus: "1",
          addPeopleName: "吴玉华",

          phone: "13313413888",
          relation: "哥哥",
          bdschool: "廊坊市第一小学",
          vistorAddress: "教学楼",
          time: "2023-07-21 12:30:56",
          status: "1",
        },
        {
          sbmc: "BJZZ-2890",
          deviceid: "489761789",
          sbType: "报警主机",
          bdSchool: "张三",
          azdz: "廊坊市第三小学",
          deviceStatus: "0",
          addPeopleName: "吴玉华",

          phone: "13313413888",
          relation: "哥哥",
          bdschool: "廊坊市第三小学",
          vistorAddress: "教学楼",
          time: "2023-07-21 16:30:56",
          status: "0",
        },
        {
          sbmc: "CLSB-5803",
          deviceid: "489761789",
          sbType: "报警主机",
          bdSchool: "张三",
          azdz: "廊坊市第三小学",
          deviceStatus: "1",
          addPeopleName: "吴玉华",

          phone: "13313413888",
          relation: "哥哥",
          bdschool: "廊坊市第三小学",
          vistorAddress: "教学楼",
          time: "2023-07-21 08:30:56",
          status: "0",
        },
      ],
      datalist: [],
      dialogVisible: false,
    };
  },
  mounted() {},

  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    submitForm() {
      console.log(this.formData);

      //    sbmc: "",
      // deviceId: "",
      // bdSchool: "",
      // deviceStatus: "",
      this.searchData.sbmc = this.formData.sbmc; // 行政区域代码
      this.searchData.deviceId = this.formData.deviceId; // 所属派出所
      this.searchData.bdSchool = this.formData.bdSchool; // 单位名称
      this.searchData.deviceStatus = this.formData.deviceStatus; // 上报人姓名
      if (this.formData.time == [] || this.formData.time == null) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = this.formData.time[1];
        this.searchData.begin_time = this.formData.time[0];
      }
      console.log(this.searchData);
    },

    handel(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.deviceVisible = e;
    },
    Confirm(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.deviceVisible = e;
    },
    handleClick(row) {
      console.log(row);
      this.Visible = !this.Visible;
      this.deviceVisible = !this.deviceVisible;
      this.detaile = row;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },

  created() {},
};
</script>
<style scoped lang="scss">
#elform {
  // display: flex;
  // flex-wrap: wrap;
  width: 100%;
  /deep/.el-form-item__content {
    margin-left: 30px !important;
  }
}
.warn-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.warn-top {
  width: calc(100%);
}
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
.warn-content {
  margin-top: 20px;
  // border: 1px red solid;
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}
// /deep/ .has-gutter .thead {
//   border: 1px red solid !important;
// }
// /deep/.el-table .thead {
//   border: 1px red solid !important;
// }
.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}

/deep/ .el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  margin-top: 0;
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 47px !important;
}
/deep/.el-input--medium .el-input__inner {
  position: relative !important;
}
.upIpfo {
  display: flex;
  width: 100%;
  //
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  //
  display: inline-block;
  // background-color: skyblue;
}
.cancel {
  width: 79px;
  height: 36px;
  background: #e6effa;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  border: none;
  color: #126bff;
  margin-right: 15px;
}
.confrim {
  width: 79px;
  height: 36px;
  background: #126bff;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  color: #ffffff;
  border: none;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}
</style>
